< previous page page_41 next page >

Page 41
The database model behind the Microsoft Access database and other SQL-oriented databases is quite different from the database model behind traditional PC databases such as FoxPro, dBASE, and Paradox. Traditional PC databases are record-oriented database systems. Structured Query Language (SQL) databases are dataset-oriented systems. Understanding the difference between record-oriented processing and dataset-oriented processing is the key to understanding how to optimize database programs in Visual Basic.
In record-oriented systems, you perform database operations one record at a time. The most common programming construct in record-oriented systems is the loop. The following pseudocode example shows how to increase the price field of an inventory table in a record-oriented database:
ReadLoop:
   If EndOf File
      Goto EndLoop
   Else
Read Record
      If Record.SalesRegion = 'Northeast' Then
         Price=Price*1.10
         Write Record
      End If
   EndIf
Goto ReadLoop
EndLoop:
End Program
Processing in record-oriented systems usually involves creating a routine that reads a single data record, processes it, and returns to read another record until the job is completed. PC databases use indexes to speed the process of locating records in data tables. Indexes also help speed processing by allowing PC databases to access the data in sorted order (by LastName, by AccountBalance, and so on).
In data-oriented systems, such as Microsoft Access, you perform database operations one set at a time, not one record at a time. The most common programming construct in set-oriented systems is the SQL statement. Instead of using program code to loop through single records, SQL databases can perform operations on entire tables from just one SQL statement. The following pseudocode example shows how you would update the price field in the same inventory file in a dataset-oriented database:
UPDATE Inventory SET Price=Price*1.10 WHERE Inventory.SalesRegion = 'Northeast'
The UPDATE SQL command behaves with SQL databases much like keywords behave with your Visual Basic programs. In this case, UPDATE tells the database that it wants to update an entire table (the Inventory table). The SET SQL command changes the value of a data field (in this case, the Price data field). The WHERE command is used to perform a logical comparison of the SalesRegion field to the value Northeast. As you can see, in dataset-oriented databases, you create a single statement that selects only the records you need to perform a database

 
< previous page page_41 next page >

If you like this book, buy it!